#include "ParamHolder.h"

// Creates a new parameter holder from a file.
// Any parameters which are not defined in the file are set to a
// default value.
ParamHolder::ParamHolder(string fn)
{
   ParamReader params(fn);

   // Set the start time.
   if (params.hasParameter("StartTime")) {
      StartTime = params.getParameterD("StartTime");
      }

   else {
      StartTime = DEFAULT_START_TIME;
      }

   // Set the stop time.
   if (params.hasParameter("StopTime")) {
      StopTime= params.getParameterD("StopTime");
      }

   else {
      StopTime= DEFAULT_STOP_TIME;
      }

   // Set the time step.
   if (params.hasParameter("dt")) {
      dt = params.getParameterD("dt");
      }

   else {
      dt = DEFAULT_DT;
      }

   // Set the tolerance parameter for the time step.
   if (params.hasParameter("TimeStepTol")) {
      TimeStepTol= params.getParameterD("TimeStepTol");
      }

   else {
      TimeStepTol= DEFAULT_TIME_STEP_TOL;
      }

   // Set the time between outputs.
   if (params.hasParameter("OutputDt")) {
      OutputDt = params.getParameterD("OutputDt");
      }

   else {
      OutputDt = DEFAULT_OUTPUT_DT;
      }

   // Set the units of mass
   if (params.hasParameter("MassUnits")) {
      MassUnits= params.getParameterD("MassUnits");
      }

   else {
      MassUnits = DEFAULT_MASS_UNITS;
      }

   // Set the units of time
   if (params.hasParameter("TimeUnits")) {
      TimeUnits = params.getParameterD("TimeUnits");
      }

   else {
      TimeUnits = DEFAULT_TIME_UNITS;
      }

   // Set the units of length
   if (params.hasParameter("LengthUnits")) {
      LengthUnits= params.getParameterD("LengthUnits");
      }

   else {
      LengthUnits= DEFAULT_LENGTH_UNITS;
      }

   // Set the gravitational constant
   if (params.hasParameter("G_cgs")) {
      G_cgs = params.getParameterD("G_cgs");
      }

   else {
      G_cgs= DEFAULT_G_CGS;
      }

   // Set the gravitational softening parameter
   if (params.hasParameter("SofteningParameter")) {
      SofteningParameter = params.getParameterD("SofteningParameter");
      }

   else {
      SofteningParameter = DEFAULT_SOFTENING_PARAMETER;
      }

   // Set the output prefix
   if (params.hasParameter("OutputPrefix")) {
      OutputPrefix= params.getParameterS("OutputPrefix");
      }

   else {
      OutputPrefix = DEFAULT_OUTPUT_PREFIX;
      }

   // Set the output column width
   if (params.hasParameter("OutputColumnWidth")) {
      OutputColumnWidth = params.getParameterI("OutputColumnWidth");
      }

   else {
      OutputColumnWidth = DEFAULT_OUTPUT_COLUMN_WIDTH;
      }

   // Set the number of characters in the output name.
   if (params.hasParameter("ZerosInOutputName")) {
      ZerosInOutputName = params.getParameterI("ZerosInOutputName");
      }

   else {
      ZerosInOutputName = DEFAULT_ZEROS_IN_OUTPUT_NAME;
      }

   // Set the opening angle.
   if (params.hasParameter("OpeningAngle")) {
      OpeningAngle= params.getParameterD("OpeningAngle");
      }

   else {
      OpeningAngle= DEFAULT_OPENING_ANGLE;
      }
}
